package com.zhang.learn.stream;

import org.junit.Test;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Stream;

/**
 * @author zhanghaolian
 * @date 2022/11/21 22:23
 */
public class StreamLearn {
    /**
     * 生物
     */
    static class Biological{ }
    /**
     * 动物
     */
    static class Animal extends Biological{ }
    /**
     * 植物
     */
    static class Plant extends Biological{ }

    static class Dog extends Animal{ }
    static class Cat extends Animal{ }
    static class Flower extends Plant{ }
    static class Tree extends Plant{ }

    public void t(List<? super Animal> list) {

    }

    /**
     * 测试流的使用
     */
    @Test
    public void test() {
        //Stream.generate(() -> "a").limit(2).forEach(s -> System.out.println(s));
        List<? super Animal> listA = new ArrayList<>();
        listA.add(new Animal());
        listA.add(new Dog());
        Object object = listA.get(0);
        //listA.add(new Biological());
        //listA.add(new Flower());

        List<? extends Plant> listB = new ArrayList<>();
        //listB.add(new Plant());
        //listB.add(new Flower());
        listB.add(null);
        Plant plant = listB.get(0);

        List<? super Biological> listC = new ArrayList<>();
        listC.add(new Cat());
        listC.add(new Animal());
        listC.add(new Tree());
    }
}
